package com.china08.yxyapi.api.manage.stu.mystudy.mistakes;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.mistakes.StuMistakesQues;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.mistakes.StuMistakesQuesRepository;

/**
 * 错题本--学生端--学科、状态、划分
 * 
 * @author LiuWeidong
 *
 */
@CrossOrigin
@RestController
public class YxyMistakesQuesSrhConditionController extends YxyApiBaseController {

    @Autowired
    private StuMistakesQuesRepository stuMistakesQuesRepository;

    @RequestMapping(value = "/api_yw/manage/stu/mystudy/mistake/condition/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody ReqModel reqModel, RespModel respModel) {

        String studentIid = reqModel.studentId;
        List<RespModel> returnList = new ArrayList<>();
        List<StuMistakesQues> stuMistakesQuesLst = stuMistakesQuesRepository.findByStudentId(studentIid);

        for (StuMistakesQues stuMistakesQues : stuMistakesQuesLst) {
            RespModel model = new RespModel();
            model.subject = stuMistakesQues.getSubject();
            model.status = stuMistakesQues.getStatus();
            model.focus = stuMistakesQues.getFocus();
            model.publishDate = stuMistakesQues.getPublishDate();
            returnList.add(model);

        }
        return returnList;
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiReqModel {

        // 学生ID
        public String studentId;

    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {

        // 学科
        public String subject;
        // 状态： 0--未消灭 1--已消灭
        public Integer status;
        // 划分：0--普通 1--重点题
        public Integer focus = 0;
        // 试题发布时间
        public Date publishDate;
    }
}
